package com.xudow.app.dynamicstate_old.module.discovery.search;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.jude.beam.expansion.list.BeamListFragmentPresenter;
import com.jude.utils.JUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by ske on 2016/6/30.
 */
public class SearchHistoryPresenter extends BeamListFragmentPresenter<SearchHistoryFragment, String> {
    @Override
    protected void onCreateView(@NonNull SearchHistoryFragment view) {
        super.onCreateView(view);
        onRefresh();
    }

    @Override
    public void onRefresh() {
        Observable.create(new Observable.OnSubscribe<List<String>>() {
            @Override
            public void call(Subscriber<? super List<String>> subscriber) {
                String history = JUtils.getSharedPreference().getString("search_history", "");
                if (TextUtils.isEmpty(history))
                    subscriber.onNext(new ArrayList<String>());
                else
                    subscriber.onNext(Arrays.asList(history.split(",")));
            }
        })
                .unsafeSubscribe(getRefreshSubscriber());
    }
}
